package com.example.shop_2305.minefg

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.lib_base.mvvm.BaseFragment
import com.example.shop_2305.R
import com.example.shop_2305.adapter.OrderAdapter
import com.example.shop_2305.databinding.FragmentOrder1Binding
import com.example.shop_2305.databinding.FragmentOrder5Binding

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
 * A simple [Fragment] subclass.
 * Use the [Order5Fragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class Order5Fragment : BaseFragment<FragmentOrder5Binding, OrderViewModel>() {
    lateinit var orderAdapter: OrderAdapter
    override fun initView() {
        orderAdapter = OrderAdapter()
        binding.rv.adapter = orderAdapter
        binding.rv.layoutManager = LinearLayoutManager(context)

        viewModel.order("-3",20,1)
    }

    override fun initData() {
        viewModel.orderSuccess.observe(this){
            if(it.code==200){
                orderAdapter.data.clear()
                orderAdapter.data.addAll(it.data.list)
                orderAdapter.notifyDataSetChanged()
            }
        }
    }

    override fun getViewModel(): Class<OrderViewModel>  = OrderViewModel::class.java

    override fun getLayout(): Int = R.layout.fragment_order5

}